class Solution {
public:
    vector<int> findAnagrams(string s, string p) {
        int hash1[26] = { 0 }, hash2[26] = { 0 };
        for (auto& e : p)
        {
            hash2[e - 'a']++;
        }
        int left = 0, right = 0, n1 = s.size(), n2 = p.size();
 
        vector<int> ret;
        if(n2 > n1)
            return ret;
        while (right < n2)
        {
            hash1[s[right++] - 'a']++;
        }
        while (right < n1)
        {
            int j = 0;
            for (; j < 26; ++j)
            {
                if (hash1[j] != hash2[j])
                {
                    break;
                }
            }
            if (j == 26)
            {
                ret.push_back(left);
            }
            hash1[s[right++] - 'a']++;
            hash1[s[left++] - 'a']--;
        }
        int j = 0;
        for (; j < 26; ++j) // 再判断一遍
        {
            if (hash1[j] != hash2[j])
            {
                break;
            }
        }
        if (j == 26)
        {
            ret.push_back(left);
        }
        return ret;
    }
};